$(document).ready(function(){
	changeImage();
});



function login() {
    $.ajax({
            url: 'user/login',
            type: "POST",
            async:false,
            data: {
            	phoneNum: $("#myemail").val(),
                password: $("#password").val(),
                checkcode: $("#checkcode").val()
            }
            ,
            success: function (data) {
            	console.log(data);
                switch (data['status']) {
                    case 0:
                    	if(data['result']['authority'] == 0){
                    		 window.location.href = "home_page.html";
                    	}else if(data['result']['authority'] == 1){
                    		window.location.href = "admin/index.html";;
                    	}
                       
                        break;
                    case -4:
                    	alert(data['msg']);
                    	changeImage();
                    	break;
                    default:
                        alert(data['msg']);
                        break;
                }
            }
            ,
            error: function (err) {
                console.log(err);
            }
        }
    );
}

//变更验证码
function changeImage() {
	 $.ajax({
         url: 'user/sendLoginCaptcha',
         type: "POST",
         async:false,
         data: {
        	 sss:"sss"
         }
         ,
         success: function (data) {
             switch (data['status']) {
                 case 0:
                	 $("#codeImg").attr('src', data['result']['verifyCode']); 
                     break;
                 default:
                     alert(data['msg']);
                     break;
             }
         }
         ,
         error: function (err) {
             console.log(err);
         }
     }
 );
}